/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmSueldos.java
 *
 * Created on 10-oct-2011, 9:32:54
 */
package apiformularios.form;

import api.dom.Camion;
import api.dom.Utilitaria;
import java.awt.print.PrinterException;
import java.text.MessageFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTable.PrintMode;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Luis
 */
public class FrmRendAndando extends javax.swing.JInternalFrame {

    /** Creates new form FrmSueldos */
    public FrmRendAndando() {
        initComponents();
        ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
        Utilitaria.listarCamionesCombo((DefaultComboBoxModel) this.jComboBox1.getModel());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnatras = new javax.swing.JButton();
        btnporpantalla = new javax.swing.JButton();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnatras1 = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setPreferredSize(new java.awt.Dimension(652, 592));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(153, 180, 209));
        jPanel1.setPreferredSize(new java.awt.Dimension(650, 71));

        jLabel6.setBackground(new java.awt.Color(51, 255, 51));
        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 48));
        jLabel6.setText("Rendimientos");
        jLabel6.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addContainerGap(366, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 662, 70));

        jLabel1.setText("Dede fecha:");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(55, 104, -1, -1));

        jLabel2.setText("Hasta fecha:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(52, 145, -1, -1));

        btnatras.setText("Atras");
        btnatras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnatrasActionPerformed(evt);
            }
        });
        getContentPane().add(btnatras, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 443, 100, 40));

        btnporpantalla.setText("Consultar");
        btnporpantalla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnporpantallaActionPerformed(evt);
            }
        });
        getContentPane().add(btnporpantalla, new org.netbeans.lib.awtextra.AbsoluteConstraints(309, 443, 100, 40));
        getContentPane().add(jDateChooser1, new org.netbeans.lib.awtextra.AbsoluteConstraints(124, 98, 340, -1));
        getContentPane().add(jDateChooser2, new org.netbeans.lib.awtextra.AbsoluteConstraints(124, 139, 340, -1));

        jLabel3.setText("Camion: ");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(72, 180, -1, -1));

        getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(124, 177, 340, -1));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Kilometros Recorridos", "GasOil Gastado", "Km/litro", "Producido", "Gastos", "Produccion/gastos"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 230, 640, 190));

        btnatras1.setText("Imprimir");
        btnatras1.setEnabled(false);
        btnatras1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnatras1ActionPerformed(evt);
            }
        });
        getContentPane().add(btnatras1, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 443, 100, 40));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnatrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnatrasActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btnatrasActionPerformed

    private void btnporpantallaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnporpantallaActionPerformed
        // TODO add your handling code here:
        try{
        Date fechaini = jDateChooser1.getDate();
        Date fechafin = jDateChooser2.getDate();
        Camion objc = (Camion) jComboBox1.getSelectedItem();
        this.jTable1.setModel(Utilitaria.kmlitro((DefaultTableModel) jTable1.getModel(), fechaini, fechafin, objc));
        btnatras1.setEnabled(true);
        }catch(NullPointerException e){
            JOptionPane.showMessageDialog(rootPane, "Seleccione las fechas entre las cuales se va a consultar");
        }

}//GEN-LAST:event_btnporpantallaActionPerformed

    private void btnatras1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnatras1ActionPerformed
        MessageFormat encabezado1 = new MessageFormat("Rendimientos");
        try {
            // TODO add your handling code here:
            jTable1.print(PrintMode.FIT_WIDTH, encabezado1, null);
        } catch (PrinterException ex) {
            Logger.getLogger(FrmRendAndando.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnatras1ActionPerformed
    /**/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnatras;
    private javax.swing.JButton btnatras1;
    private javax.swing.JButton btnporpantalla;
    private javax.swing.JComboBox jComboBox1;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
